package com.ms.db.usertype;

import java.util.ArrayList;
import java.util.List;

import com.xpec.c4.db.util.CodecTool;
import com.xpec.c4.game.utility.GUID;

public class ArrayListGuidToString extends BasicToString{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5822642227889260444L;

	@SuppressWarnings("unchecked")
	@Override
	protected String assemble(Object obj) {
		List<GUID> arrayList = (List<GUID>)obj;
		StringBuilder strBui = new StringBuilder();
		for (int i = 0; i < arrayList.size() - 1; i++) {
			CodecTool.append(strBui,GUID.toString(arrayList.get(i)),SPLITTER);
		}
		if (arrayList.size() > 0) {
			strBui.append(GUID.toString(arrayList.get(arrayList.size() - 1)));
		}
		return strBui.toString();
	}

	@Override
	protected Object parse(String value) {
		if(value==null){
			return null;
		}
		List<GUID> list = new ArrayList<GUID>();
		if (value == null || value.length() <= 0) {
			return list;
		}
		String[] strs=CodecTool.split(value, SPLITTER);
		for (int i = 0; i < strs.length; i++) {
			list.add(GUID.parseUUID(strs[i]));
		}
		return list;
	}

	
	public int[] sqlTypes() {

		return CLOB_TYPES;
	}

	public Class<?> returnedClass() {
		return List.class;
	}
}
